package com.jic.point.controller.feign;

import com.alibaba.fastjson.JSON;
import com.jic.point.api.RightsAndInterestsAuditAPi;
import com.jic.point.common.Result;
import com.jic.point.model.entity.ConfActivityRuleApply;
import com.jic.point.rest.request.Audit;
import com.jic.point.rest.request.Rights;
import com.jic.point.rest.request.RightsNo;
import com.jic.point.rest.response.RightsResponse;
import com.jic.point.service.ConfActivityRuleApplyService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName RightsAndInterestsAuditCilent
 * TODO
 * @Description 调用活动
 * @Author chenhongfeng
 * @Date 2020/11/25 18:14
 * @Version 1.0
 **/
@Api(tags = {"Feign-权益"})
@RequestMapping(value = "/api/point/rights")
@RestController
@Slf4j
public class RightsAndInterestsAuditCilent implements RightsAndInterestsAuditAPi {

    //调用活动申请表
    @Autowired
    ConfActivityRuleApplyService confActivityRuleApplyService;
    /**
     * 活动删除接口，删除一个处于新建状态(未经审批)的活动")
     * @param rights
     * @return
     */
    @PostMapping("/delete")
    @Override
    public Result<Integer> deleteNewActivity(Rights rights){
        log.info("入参{}", JSON.toJSONString(rights));
        ConfActivityRuleApply confActivityRuleApply=new ConfActivityRuleApply();
        confActivityRuleApply.setCode(rights.getRulecode());
        Result<Integer> integerResult = confActivityRuleApplyService.updateByCode(confActivityRuleApply);
        log.info("出参{}", JSON.toJSONString(integerResult));
        return integerResult;
    }

    /**
     * *根据权益编码审核通过权益
     *      审核活动
     * @param audit
     * @return
     */
    @PostMapping("/auditActivity")
    @Override
    public Result<Integer> auditActivity(@RequestBody Audit audit) {
        log.info("入参{}", JSON.toJSONString(audit));
        ConfActivityRuleApply confActivityRuleApply=new ConfActivityRuleApply();
        confActivityRuleApply.setCode(audit.getCode());
        confActivityRuleApply.setAuditSts(audit.getAuditSts());
        confActivityRuleApply.setAuditReason(audit.getAuditReason());
        Result<Integer> integerResult = confActivityRuleApplyService.updateByCodeAudit(confActivityRuleApply);
        log.info("出参{}", JSON.toJSONString(integerResult));
        return integerResult;
    }

    /**
     * 权益活动配置-权益提交
     *  新增/修改购机权益配置
     * @param rightsNo
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @Override
    public Result<RightsResponse> saveOrUpdate(RightsNo rightsNo) {
        return null;
    }
}
